/*******************************************************************************
 * Copyright (c) 2009 Kevin Bierhoff and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Kevin Bierhoff - initial API and implementation
 *******************************************************************************/
package com.googlecode.twelfdevtools.twelfast;

public class Pi implements ITwelfTerm {
	
	public static Pi pi(Identifier x, ITwelfTerm vt, ITwelfTerm t) {
		return new Pi(x, vt, t);
	}

	private Identifier id;
	private ITwelfTerm idTerm;
	private ITwelfTerm term;
	
	public Pi(Identifier id, ITwelfTerm idTerm, ITwelfTerm term) {
		super();
		this.id = id;
		this.idTerm = idTerm;
		this.term = term;
	}

	public Identifier getId() {
		return id;
	}

	public ITwelfTerm getIdTerm() {
		return idTerm;
	}

	public ITwelfTerm getTerm() {
		return term;
	}
	
	public <T> T dispatch(ITwelfAstVisitor<T> visitor) {
		return visitor.pi(this);
	}

	@Override
	public String toString() {
		return "{" + id + ":" + idTerm + "}" + term;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((term == null) ? 0 : term.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((idTerm == null) ? 0 : idTerm.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Pi other = (Pi) obj;
		if (term == null) {
			if (other.term != null)
				return false;
		} else if (!term.equals(other.term))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (idTerm == null) {
			if (other.idTerm != null)
				return false;
		} else if (!idTerm.equals(other.idTerm))
			return false;
		return true;
	}

}
